<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\User as userModel;

class User extends Base {
    public function index(){
        //接收 && 定义参数
        $userModel = new userModel();
        $page = '';
        //用户列表
        $data = $userModel -> getUserList(false,'uid desc',10,$page);

        $this -> assign('data',$data);//数据
        $this -> assign('page',$page);//分页
        return view();
    }

    /*  添加用户   */
    public function add_member(){
        $info = input('post.');
        if(empty($info)){
            return view();
        }else{
            $userModel = new userModel();
            $add['username'] = $info['username'];//用户名
            $add['password'] = encryptPass($info['pass']);//密码
            $add['addtime'] = time();
            $result = $userModel -> addUser($add);
            if(empty($result)){
                echo 0;
            }else{
                echo 1;
            }
        }
    }

    /*  修改用户信息
     *  @param get field 'type,uid'
     *  @param post array [password,uid]
     * **/
    public function modify(){
        $info = input('post.');
        if(empty($info)){
            $data = input('get.');
            //分配变量
            $this -> assign('data',$data);
            return view();
        }else{
            dump($info);
        }
    }

    /*  删除用户
     *  @param field "uid"
     * **/
    public function modifyUserData(){
        $userModel =  new userModel();
        $uid = input('post.uid');
        $status = input('post.status');
        $where['uid'] = $uid;
        $save['status'] = $status;
        $result = $userModel -> modifyUserData($where,$save);
        if(empty($result)){
            return ['code'=>400,',msg'=>'ERROR'];
        }else{
            return ['code'=>200,'msg'=>'SUCCESS'];
        }


    }


}
